<%@ page import="id.co.gomobile.assessment.User" %>
<%@ page import="id.co.gomobile.assessment.Profile"%>
<%@ page import="id.co.gomobile.assessment.Role"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <title>Edit Profile</title>
    </head>
    <body>
    <g:render template="/shared/navigation" />
    
    <div id="body">
    
    <h1>Edit Profile</h1>
    
    <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
    </g:if>

    <g:hasErrors bean="${userInstance}">
    <div class="errors">
        <g:renderErrors bean="${userInstance}" as="list" />
    </div>
    <br/>
    </g:hasErrors>

    <g:form action="updateProfile" method="post" >
        <g:hiddenField name="id" value="${userInstance?.id}" />
        <g:hiddenField name="version" value="${userInstance?.version}" />

    <div class="form">

    <fieldset>
        <h3>Login Information</h3>
        
        <br/>
        
        <label for="username" class="required ${hasErrors(bean: userInstance, field: 'username', 'errors')}">Username :</label>
        <div class="value">
            <g:textField name="username" maxlength="64" value="${userInstance?.username}" readonly="true" />
        </div>
        <div class="notes">Username may contains alphanumeric, with length of 4 to 64 characters.</div>
        
        <br/>
        
        <label for="email" class="required ${hasErrors(bean: userInstance, field: 'email', 'errors')}">Email :</label>
        <div class="value">
            <g:textField name="email" value="${userInstance?.email}" />
        </div>
        <div class="notes">A valid email address must be provided.</div>
        
        <br/>
        <br/>
        
        <h3>Personal Information</h3>
        
        <br/>
        
        <label for="profile.fullname" class="required ${hasErrors(bean: userInstance, field: 'profile.fullname', 'errors')}">Fullname :</label>
        <div class="value">
            <g:textField name="profile.fullname" value="${userInstance?.profile?.fullname}" />
        </div>
        <div class="notes">Fullname may contains alphanumeric and space.</div>
        
        <br/>

        <label for="profile.birthdate" class="required ${hasErrors(bean: userInstance, field: 'profile.birthdate', 'errors')}">Birthdate :</label>
        <div class="value">
            <g:datePicker name="profile.birthdate" precision="day" value="${userInstance.profile?.birthdate}"  />
        </div>
        
        <br/>

        <label for="profile.gender" class="${hasErrors(bean: userInstance, field: 'profile.gender', 'errors')}">Gender :</label>
        <div class="value">
            <g:select name="profile.gender" from="${Profile.constraints.gender.inList}" value="${userInstance?.profile?.gender}" valueMessagePrefix="profile.gender"  />
        </div>

        <br/>
        
        <label for="profile.address" class="${hasErrors(bean: userInstance, field: 'profile.address', 'errors')}">Address :</label>
        <div class="value">
            <g:textArea name="profile.address" value="${userInstance?.profile?.address}" />
        </div>

        <br/>

        <label for="profile.phone" class="required ${hasErrors(bean: userInstance, field: 'profile.phone', 'errors')}">Phone :</label>
        <div class="value">
            <g:textField name="profile.phone" value="${userInstance?.profile?.phone}" />
        </div>

        <br/>

        <label for="profile.description" class="${hasErrors(bean: userInstance, field: 'profile.description', 'errors')}">Description :</label>
        <div class="value">
            <g:textArea name="profile.description" value="${userInstance?.profile?.description}" />
        </div>
        <div class="notes">Write anything that describe yourself.</div>

        <br/>
        <br/>

        <div class="buttons">
            <span class="button"><g:submitButton name="update" class="save" value="${message(code: 'default.button.update.label', default: 'Update')}" /></span>
        </div>
    </fieldset>

    </div>
    </g:form>
    
    </div>
    </body>
</html>